aboutsummaryrefslogtreecommitdiff
path: root/src/pages/blog/[...slug].astro
blob: 9262a66b2c01b4cd77b3ad0d87a66327279676bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
import { type CollectionEntry, getCollection } from "astro:content";
import Comments from "../../components/Comments.astro";
import Layout from "../../layouts/PageLayout.astro";
import Pagination from "../../components/PostPagination.astro";

export async function getStaticPaths() {
	const posts = await getCollection("blog");
	const total = posts.length;

	return posts.map((post, index) => ({
		params: { slug: post.slug },
		props: {
			post,
			prevPost: index + 1 === total ? null : posts[index + 1],
			nextPost: index === 0 ? null : posts[index - 1],
		},
	}));
}
type Props = CollectionEntry<"blog">;

const { post, prevPost, nextPost } = Astro.props;
const { Content, remarkPluginFrontmatter } = await post.render();
---

<style>
	.header {
		text-align: center;
	}
</style>

<Layout title={post.data.title} description={post.data.description}>
	<article>
		<section class="header">
			<h1>{post.data.title}</h1>
			<p>
				<small>
					Posted
					<time datetime={post.data.pubDate.toISOString()}>{post.data.pubDate.toDateString()}</time>
					&nbsp;by&nbsp;{post.data.author}&nbsp;‐
					<strong>{remarkPluginFrontmatter.minutesRead}</strong>
				</small>
			</p>
		</section>

		<section>
			<Content />
		</section>

		<section>
			<Pagination prevPost={prevPost} nextPost={nextPost} />
		</section>

		<section>
			<Comments />
		</section>
	</article>
</Layout>